const fp = require('lodash/fp');

const { Maybe, Container } = require('./support')

let maybe = Maybe.of([5, 6, 1]);

let safeProp = fp.curry(function(x, o) {
    return Maybe.of(o[x])
})

let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])

let user = { id: 2, name: 'Albert' }

//练习1
let ex1 = (num) => {
    // 需要实现的函数 do something
    return maybe.map(fp.map(x => fp.add(x, num)))._value;
}
console.log(ex1());

//练习2
let ex2 = () => xs.map(fp.first)._value;

//练习3
let ex3 = fp.flowRight(fp.map(i => fp.first(i)), safeProp('name'))
console.log(ex3(user)) // A

//练习4
let ex4 = n => fp.flowRight(fp.first, fp.map(parseInt), Maybe.of)(n);